package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Region4Hotel;
import cn.wolfcode.luowowo.article.repository.IRegion4HotelRepository;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegion4HotelService;
import cn.wolfcode.luowowo.article.vo.DestInRegionVO;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.ArrayList;
import java.util.List;

@Service
public class Region4HotelServiceImpl implements IRegion4HotelService {

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IRegion4HotelRepository repository;

    @Autowired
    private MongoTemplate template;

    @Override
    public List<DestInRegionVO> queryDestInRegion() {
        List<Region4Hotel> all = template.findAll(Region4Hotel.class);
        List<DestInRegionVO> list = new ArrayList<>();
        for (Region4Hotel region4Hotel : all) {
            DestInRegionVO vo = new DestInRegionVO();
            vo.setRegion(region4Hotel.getRegion());
            List<Destination> dests = destinationService.getDestsByIds(region4Hotel.getDests());
            vo.setDests(dests);
            list.add(vo);
        }
        return list;
    }
}
